<!--
* description: 缺件查询
* author: xiaochengzuan
* createdDate: 2021-1-28
-->

<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-api-config="dynamicApiConfigs"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-api-style="'restful'"
      :callback-obj="callbackObj"
    />

    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />
  </div>
</template>
<script>

import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'
import { orgApis } from "@/api/pabasicdataapi";
import { exportExcel } from '@/utils/getTimeString.js'


export default {
  name: 'shortageInquiry',

  components: {
    OneTableTemplate,
    // Edit: () => import('./edit')
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {

    // this.$refs['multipleTable'].data = [{bigAreaCode:'1'}]
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      editRowData: {},
      // 网格查询API配置对象
      // apiConfig: {
      //   ServiceCode: 'queryBigArea',
      //   APIUrl: '/mp/e3sh/basics/ve/bigareaService/queryBigArea.do'
      // },
      dynamicApiConfigs: orgApis.shortageInquiryQuery,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          position: 'right',
          fuzzySearch: true
        },
        //    {
        //   compKey: 'btnKey3',
        //   type: '',
        //   size: 'small',
        //   name: 'add',
        //   clickEvent: this.add,
        //   text: this.$t('sys.button.add'), // 新增
        //   position: 'left'
        // },
          // {
          //   compKey: 'comKey3',
          //   type: '',
          //   size: 'small',
          //   name: '',
          //   position: 'right',
          //   // clickEvent: () => this.submit(),
          //   // clickEvent: this.add,
          //   text: '提交',
          //   disabled: false
          // },
        //  {
        //   compKey: 'btnKey3',
        //   type: '',
        //   size: 'small',
        // //   clickEvent: () => this.batchDelete(),
        // // clickEvent: this.add,
        //   text: '作废',
        //   name: '',
        //   position: 'right',
        // //   fuzzySearch: true
        // },
           {
              compKey: 'btnKey3',
              type: '',
              size: 'small',
              name: 'export',
              position: 'right',
              clickEvent: () => this.exportExcel1(), //导出
              text: '导出',
            
            },
        {
          compKey: 'btnKey2',
          type: '',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        },
        //      {
        //   compKey: 'btnKey2',
        //   type: '',
        //   size: 'small',
        //   name: 'reset',
        // //   clickEvent: () => this.reset(),
        //   text: '导入',
        //   position: 'left' // 导入
        // },
     
       
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [

              {
              compKey: 'compKey1',
              labelName: '网点编码：',
              codeField: 'dlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true,
              disabled: true
            },

              {
              compKey: 'compKey2',
              labelName: '缺件单号：',
              codeField: 'lackPartsCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },

                       {
              compKey: 'compKey3',
              labelName: '车牌号：',
              codeField: 'carLicense',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },

                   {
              compKey: 'compKey4',
              labelName: '缺件状态：',
              codeField: 'lackPartsStatus',
              component: () => import('@/components/org/commonSelect'),
              customObj: {
                api: orgApis.queryLackPartStatus,
              },
              type: 'dropdownList',
              isMul: false,
              isMust: true
            },

              {
              compKey: 'compKey5',
              labelName: '关联单号：',
              codeField: 'associationNo',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },

              {
              compKey: 'compKey6',
              labelName: '登记人员：',
              codeField: 'registerPerson',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },

                     {
              compKey: 'compKey7',
              labelName: '登记日期：',
              codeField: 'startDate,endDate',
              component: () => import('@/components/org/datePicker/andtDatePicker'),
              type:'YYYY-MM-DD',
              format: 'yyyy-MM-dd',
              dateOptionsType: '0',
              isMul: false,
              isMust: false
            },

              {
              compKey: 'compKey8',
              labelName: '紧急度：',
              codeField: 'urgency',
              component: () => import('@/components/org/LookupValue'),
              oFields: 'statusId,statusText',
              options: [
                { statusId: '1', statusText: '紧急' },
                { statusId: '0', statusText: '一般' }
              ],
              type: 'dropdownList',
              isMul: false,
              isMust: false
            },


          
            {
              compKey: 'compKey9',
              labelName: 'VIN：',
              codeField: 'vin',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },
                         {
              compKey: 'compKey10',
              labelName: '客户名称：',
              codeField: 'customerName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },

                           {
              compKey: 'compKey11',
              labelName: '备件编号：',
              codeField: 'partNo',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },

                           {
              compKey: 'compKey12',
              labelName: '备件名称：',
              codeField: 'partName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },
        

        
        
          
             
            //           {
            //   compKey: 'compKey7',
            //   labelName: '车型编码：',
            //   codeField: 'bigAreaName7',
            //   component: () => import('@/components/org/commonInput'),
            //   type: 'inputText',
            //   isMul: false,
            //   isMust: false
            // },
         
            //   {
            //   compKey: 'compKey4',
            //   labelName: '所属期间：',
            //   codeField: 'bigAreaName3',
            //   component: () => import('@/components/org/datePicker/andtDatePicker'),
            //   type: 'andtDatePicker',
            //   isMul: false,
            //   isMust: true
            // },
           
         
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'releaseId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            // {
            //   prop: 'controlBtn1',
            //   label: '操作',
            //   minWidth: 180,
            //   isComponent: true,
            //   comps: [
            //     {
            //       compKey: 'propKey1',
            //       labelName: '修改',
            //       component: () => import('@/components/org/linkButton'),
            //       clickEvent: (index) => this.edit(index)
            //     },
            //        {
            //       compKey: 'propKey1',
            //       labelName: '作废',
            //       component: () => import('@/components/org/linkButton'),
            //       clickEvent: (index) => this.edit(index)
            //     }
            //   ]
            // },

              {
              prop: 'dlrShortName',
              label: '网点名称'
            },
            {
              prop: 'lackPartsCode',
              label: '缺件单号',
              hidden: false,
            //   alwaysHidden: true
            },
            {
              prop: 'customerName',
              label: '客户姓名'
            },
                 {
              prop: 'customerPhone',
              label: '联系电话'
            },
                 {
              prop: 'carLicense',
              label: '车牌号'
            },
                  {
              prop: 'vin',
              label: 'VIN码'
            },
                   {
              prop: 'urgencyCn',
              label: '紧急度'
            },
                   {
              prop: 'registerPerson',
              label: '登记人员'
            },
                   {
              prop: 'registerDate',
              label: '登记日期'
            },
                   {
              prop: 'associationNo',
              label: '关联单号'
            },
                   {
              prop: 'associationTypeCn',
              label: '关联类型'
            },
                   {
              prop: 'partNo',
              label: '备件编码'
            },
            {
              prop: 'partName',
              label: '备件名称'
            },
            {
              prop: 'unit',
              label: '单位'
            },
            {
              prop: 'lackPartsStatusCn',
              label: '审核状态'
            },
            {
              prop: 'expectedDeliveryDate',
              label: '希望到货日期'
            },
            {
              prop: 'accountQty',
              label: '当前库存数量'
            },
            {
              prop: 'lackQty',
              label: '缺件数量'
            },
            {
              prop: 'frozenQty',
              label: '转订单数'
            },
            {
              prop: 'usableStockQty',
              label: '已分配数',
              hidden: true
            }
          ],
          
      // 表单查询数据
      formField: this.$utils.getFormField(this, {
        dlrCode: '',
        lackPartsCode: '',
        carLicense: '',
        lackPartsStatus: '',
        associationNo: '',
        registerPerson: '',
        startDate: '',
        endDate: '',
        urgency: '',
        vin: '',
        customerName: '',
        partNo: '',
        partName: '',
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode]),

       callbackObj: {
        onQueryReturn:(response)=>{
          this.geCurrentQuantity(response)
        }
      },
    }
  },

mounted() {
    this.formField.dlrCode = this.$store.getters.orgInfo.DLR_CODE
    // 列表查询
    this.queryTable(1)
    this.$refs.multipleTable.list = [
      {'releaseId':'1'}
    ]
  },

  methods: {
    // 编辑获取数据
    edit(index) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true
      this.editRowData = this.$utils.deepCopy(this.$refs['multipleTable'].list[index])
    },

     exportExcel1(){
      //导出
      // outsourcingsupplierqueryexportexcel

       exportExcel(this.formField, orgApis.shortageInquiryQueryExport.APIUrl, orgApis.shortageInquiryQueryExport.ServiceCode, '缺件查询')

    },
    // 当前库存数量为null时，显示0
    geCurrentQuantity(response){
      let arr=response.rows
      for(let a=0;a<arr.length;a++){
        if(arr[a].accountQty === null){
          arr[a].accountQty = "0"
        }
      }
    }
      


        //导出
   /*  export() {
      var date = new Date;
      var year=date.getFullYear()
      var month=date.getMonth()+1
      var day=date.getDate();
          month =(month<10 ? "0"+month:month)
          day =(day<10 ? "0"+day:day)
      var mydate = year.toString()+month.toString()+day.toString()
      const returnObj = {
          // api配置
        apiConfig: {
          APIUrl:'/mp/e3sh/basics/ve/CarTypeService/exportCarType.do',
        },
          variables: this.formField
        }
        returnObj.variables.dataType='excel'
        const paramD = this.$getParams(returnObj)
        this.$requestAPI(paramD).then(res=>{
        this.$utils.downloadFile(res,`车系维护${mydate}.xlsx`)
      })
    }, */
  }
}
</script>
